﻿/*******************************************************************************
 * AAEngine
 * Copyright (c) 2010 Mike Jarosch
 *
 * Original source PushButton Engine:
 * Copyright (C) 2009 PushButton Labs, LLC
 * For more information see http://www.pushbuttonengine.com
 *
 * This file is licensed under the terms of the MIT license, which is included
 * in the "MIT License.txt" file at the root directory of this SDK.
 ******************************************************************************/

namespace AAEngine.Sound
{
    /// <summary>
    /// State pertaining to a whole category of sounds. See ISoundManager for more
    /// complete explanation, as this class is mostly used internally.
    /// </summary>
    sealed public class SoundCategory
    {
        public bool Muted { get; set; }

        public bool IsDirty { get; set; }

        public float Volume 
        {
            get { return _volume; }
            set { _volume = value; }
        }
        private float _volume = 1;
        
        public float Pan { get; set; }

        internal static SoundTransform ApplyCategoriesToTransform(bool muted, float pan, float volume, params SoundCategory[] categories)
        {
            for (int i = 0; i < categories.Length; i++)
            {
                SoundCategory c = categories[i];

                if (c.Muted)
                {
                    muted = true;
                }

                volume *= c.Volume;
                pan += c.Pan;
            }

            return new SoundTransform()
                {
                    Volume = muted ? 0 : volume,
                    Pan = pan
                };
        }
    }
}
